﻿


namespace Orid.Management.SOHO.Book.Client.Logic
{

    using Orid.Management.Component;
    using System; 
    using Orid.Management.Common.Job;

    internal class UtilScoreResult
    {
        SOHOProxy proxy = null;

        private string serverAddress { get; set; }

        public UtilScoreResult(string address)
        {
            serverAddress = address;
        }

        public UtilScoreResult(SOHOProxy proxy)
        {
            this.proxy = proxy;
        }

        private SOHOProxy Proxy
        {
            get
            {
                if (proxy == null)
                {
                    try
                    {
                        proxy = new SOHOProxy(serverAddress);
                    }
                    catch
                    {
                        return null;
                    }
                }

                return proxy;
            }
        }

        public  Orid.Management.Common.Job.JobStatistics[] GetUserJobCount(string loginName,int year,int month)
        {
            string beginDateTime =new DateTime(year, month, 1).ToString("yyyy-MM-dd");
            string endDateTime = new DateTime(year, month, 1).AddMonths(1).ToString("yyyy-MM-dd");

            JobStatistics[] listResult = GetEntryScoreResult(loginName, 2, beginDateTime, endDateTime);

            return listResult;
        }

        public  Orid.Management.Common.Job.JobStatistics[] GetUserJobCountDetail(string loginName, int year, int month)
        {
            string beginDateTime = new DateTime(year, month, 1).ToString("yyyy-MM-dd");
            string endDateTime = new DateTime(year, month, 1).AddMonths(1).ToString("yyyy-MM-dd");

            JobStatistics[] listResult = GetEntryScoreResult(loginName, 1,beginDateTime, endDateTime);

            return listResult;
        }

        private JobStatistics[] GetEntryScoreResult(string loginName, int kind,string beginDateTime, string endDateTime)
        {
             JobStatistics[] listResult = null;
            try
            {
                listResult =  Proxy.GetUserDeliveryJobCount(loginName, kind,
                                                 beginDateTime,
                                                 endDateTime);
            }
            catch  
            { 
                return listResult;
            }

            return listResult;
        }
         
    }
}
